package fm.dongman.modellib.local;

import android.content.Context;

import org.jetbrains.annotations.NotNull;

import fm.dongman.animefm.contractlib.contract.FSheetContract;
import fm.dongman.animefm.contractlib.model.FSheetDataModel;

/**
 * Sheet本地源
 * Created by KUIGE on 2017/10/15.
 */

public class FSheetLocalDataSource implements FSheetContract.IFSheetDataSource {

    private static FSheetLocalDataSource SINGLETON;

    private Context mContext;

    //将数据保存到数据库中
    private DataOperationHelper mDataOperationHelper;

    private FSheetLocalDataSource(Context context)
    {
        mContext = context;
        mDataOperationHelper = DataOperationHelper.getDataOperationHelper(context);
    }

    public static FSheetLocalDataSource getInstance(Context context) {
        if (SINGLETON == null)
        {
            SINGLETON = new FSheetLocalDataSource(context);
        }
        return SINGLETON;
    }

    @Override
    public void getData(@NotNull LoadSourceCallback<? super FSheetDataModel> callback) {
        FSheetDataModel model = mDataOperationHelper.downSheetDataModel();
//            Log.e("++++++++","    ssssss");
            callback.onDataLoaded(model);
    }

    @Override
    public void saveData(FSheetDataModel dataModel) {
//        Log.e("保存数据","-------------"+dataModel.getMLabels().size());
        mDataOperationHelper.addFSheetDaren(dataModel.getMasters());
        mDataOperationHelper.addFSheetList(dataModel.getSheets());
        mDataOperationHelper.addFSheetSpec(dataModel.getSpecials());
        mDataOperationHelper.addFSheetTopic(dataModel.getMLabels());
    }

    @Override
    public void refreshData() {

    }

    @Override
    public void offLine() {

    }
}
